package net.asfun.jvalog.http;

import java.io.Serializable;

import javax.servlet.http.HttpServletResponse;

public class ResponseHandle implements Serializable{

	private static final long serialVersionUID = 200904291709L;
	private String encoding = "utf-8";
	private int size = 0;
	private int ttl = 3600;
	private String mime = "text/html";

	public void setHeaders(HttpServletResponse resp) {
		if ( encoding != null && !"".equals(encoding.trim()) )
			resp.setCharacterEncoding(encoding);
		if ( size > 0)
			resp.setContentLength(size);
		if ( mime != null && !"".equals(mime.trim()) )
			resp.setContentType(mime);
		if ( ttl == 0 ) {
			resp.setHeader("Cache-Control","no-store");
			resp.setHeader("Pragma","no-cache");
			resp.setDateHeader("Expires", 0);
		}
	}
	
	public void success(HttpServletResponse resp, String message) {
		setHeaders(resp);
	}
	
	public void setMime(String mime) {
		this.mime = mime;
	}
	
	public void setSize(int size) {
		this.size = size;
	}
	
	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}
	
	public void setCache(int ttl) {
		this.ttl = ttl;
	}
}
